import { Global } from "../../../../com/gengine/global/Global";
import { ObjCreate } from "../common/ObjCreate";
import { GTileList } from "../../../../com/mui/controls/GTileList";
import { ScrollBarDirection } from "../../../../fl/controls/ScrollBarDirection";
import { SearchStringRenderer } from "./SearchStringRenderer";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { GScrollPane } from "../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { ItemInfo } from "../../resource/info/ItemInfo";
import { SearchConditionData } from "./SearchConditionData";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
//class SearchStringList
    
    export  class SearchStringList /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._itemArr = [];
            this.init();
            addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStageHandler);
            return;
        }

        /* internal  */onAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            Global.stage.addEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1: Object /* flash.events.Event */): void
        {
            Global.stage.removeEventListener(flash.events.MouseEvent.CLICK, this.onMouseClickHandler);
            removeEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._bg = ObjCreate.createBg(0, 0, 120, 140, this);
            this._tileList = new GTileList();
            this._tileList.setSize(120, 140);
            this._tileList.columnWidth = 120;
            this._tileList.rowHeight = 20;
            this._tileList.direction = ScrollBarDirection.VERTICAL;
            this._tileList.horizontalGap = 0;
            this._tileList.verticalGap = 0;
            this._tileList.styleName = "TileList";
            this._tileList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._tileList.setStyle("cellRenderer", SearchStringRenderer);
            this._tileList.move(0, 0);
            this._tileList.dataProvider = new DataProvider();
            addChild(this._tileList);
            this._scrollPane = new GScrollPane();
            this._scrollPane.x = 0;
            this._scrollPane.y = 0;
            this._scrollPane.width = 120;
            this._scrollPane.height = 140;
            this._scrollPane.styleName = "GScrollPane";
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.source = this._tileList;
            this._scrollPane.scrollDrag = false;
            this._scrollPane.setScrollBarSize(19);
            addChild(this._scrollPane);
            this._scrollPane.update();
            return;
        }

        public updateDataProvider(arg1: Array<any>): void
        {
            this._itemArr = arg1;
            this._tileList.dataProvider = new DataProvider(arg1);
            this._scrollPane.update();
            if (arg1.length < 7) 
            {
                this._bg.height = arg1.length * 20;
            }
            else 
            {
                this._bg.height = 140;
            }
            return;
        }

        /* internal  */onMouseClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            var loc2=this._itemArr[0].itemInfo as ItemInfo;
            if (loc2) 
            {
                loc1[loc2.item.code] = loc2.item.code;
                SearchConditionData.codesMap = loc1;
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSearchItemSelect, loc2));
            }
            return;
        }

        /* internal */ /* var */_tileList: GTileList;

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_bg: ScaleBitmap;

        /* internal */ /* var */_itemArr: Array<any>;
    }
